import sys
from PyQt5.QtCore import QObject, QUrl
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQml import QQmlApplicationEngine


class LoginHandler(QObject):
    def __init__(self):
        super().__init__()

    def loginClicked(self, username, password):
        # 在这里处理登录逻辑
        print("Username:", username)
        print("Password:", password)


if __name__ == "__main__":
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()

    # 注册LoginHandler对象为上下文属性，以便在QML中访问
    login_handler = LoginHandler()
    engine.rootContext().setContextProperty("loginHandler", login_handler)

    # 加载并显示QML文件
    engine.load(QUrl.fromLocalFile("./login.qml"))
    if not engine.rootObjects():
        sys.exit(-1)

    sys.exit(app.exec_())
